<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mc">
              <a-input v-model="model.mc" placeholder="请输入名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属电站" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ssdzId">
              <j-dict-select-tag type="list" v-model="model.ssdzId" dictCode="sb_cdz,mc,id" placeholder="请选择所属电站" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="充电机地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cdjdz">
              <a-input v-model="model.cdjdz" placeholder="请输入充电机地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="IP" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cdjip">
              <a-input v-model="model.cdjip" placeholder="请输入IP"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="Port" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cdjport">
              <a-input v-model="model.cdjport" placeholder="请输入Port"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="协议" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xyId">
              <j-dict-select-tag type="list" v-model="model.xyId" dictCode="sb_xy,xyms,id" placeholder="请选择协议" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="厂商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cs">
              <a-input v-model="model.cs" placeholder="请输入厂商"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xh">
              <a-input v-model="model.xh" placeholder="请输入型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出厂编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ccbh">
              <a-input v-model="model.ccbh" placeholder="请输入出厂编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="厂家型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cjxhId">
              <j-dict-select-tag type="list" v-model="model.cjxhId" dictCode="sb_cjxh,xhms,id" placeholder="请选择厂家型号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="充电机类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cdjlxId">
              <j-dict-select-tag type="list" v-model="model.cdjlxId" dictCode="sb_cdjlx,lxms,id" placeholder="请选择充电机类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模块个数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mkgs">
              <a-input v-model="model.mkgs" placeholder="请输入模块个数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="终端个数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zdgs">
              <a-input v-model="model.zdgs" placeholder="请输入终端个数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="容量/KW" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rongliang">
              <a-input v-model="model.rongliang" placeholder="请输入容量/KW"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jd">
              <a-input v-model="model.jd" placeholder="请输入经度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="纬度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wd">
              <a-input v-model="model.wd" placeholder="请输入纬度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scrq">
              <j-date placeholder="请选择生产日期" v-model="model.scrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生产商代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scsdm">
              <a-input v-model="model.scsdm" placeholder="请输入生产商代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <a-input v-model="model.bz" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="充电时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cdsj">
              <a-input v-model="model.cdsj" placeholder="请输入充电时间"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SbCdzhuangForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/sbcdzhuang/sbCdzhuang/add",
          edit: "/sbcdzhuang/sbCdzhuang/edit",
          queryById: "/sbcdzhuang/sbCdzhuang/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>